<?php
error_reporting("E_ALL");ini_set("display_errors", 1);
$getdata=$_REQUEST;
if(empty($getdata))$getdata=$_POST?$_POST:$_GET;
$type=empty($getdata['type'])?'':$getdata['type'];
$id=empty($getdata['id'])?'':$getdata['id'];
include("include/function.php");
//header("content-Type: application/json; charset=utf-8");
$config = include("config.php");
include("include/".$config['DB_TYPE'].".class.php");
$db = new db;
$db->connect($config['DB_HOST'],$config['DB_USER'],$config['DB_PWD'],$config['DB_NAME'], $config['DB_PCONNECT']);
$where="pay_status=20 and new_class_id<>''";	
if($id){
    $where.=" and order_id>".$id;
}
$sql = "select * from hema_food_order where ".$where." order by order_id limit 1000";
$list = $db->get_all($sql);$insert=0;if(empty($list))exit('over');
$class=[];$sqlarr=[];
foreach($list as $v){
    $class_arr = explode('级',str_replace('班','',str_replace('.','级',$v['new_class_name'])));
    $class_num = $class_arr[1];
    if(empty($class_num)){
        $arr = array('四一班'=>1,'四二班'=>2,'二一班'=>1);
        $class_num = $arr[$v['new_class_name']];
    }
    if(empty($class_num)){
        echo $v['new_class_name']."\n";
    }
    $sqlarr[]="update hema_food_order set class_id='".$v['new_class_id']."',class_name='".$v['new_class_name']."',class_num='".$class_num."' where student_id=".$v['student_id'].';';
    $sqlarr[]="update hema_food_order_detail set class_id='".$v['new_class_id']."',class_name='".$v['new_class_name']."',class_num='".$class_num."' where student_id=".$v['student_id'].';';
    $sqlarr[]="update hema_feedback set class_id='".$v['new_class_id']."',class_name='".$v['new_class_name']."' where student_id=".$v['student_id'].';';
    $sqlarr[]="update hema_student set class_id='".$v['new_class_id']."' where student_id=".$v['student_id'].';';
   /*$db->query("update hema_school_class set school_uuid='".$v['uuid']."' where school_id=".$v['school_id']);  */
}
//$log = $id.'导入成功,：'.$insert.'条';$page=0;
//echo $log.'<script>location.href="?page='.$page.'&id='.$id.'";</script>';

echo count($sqlarr)."\n";
echo implode("\n",$sqlarr);
?>